"""
@Date:2022/8/5
@author:Jingyu
@Description：解决登录，退出，获取页面对象
@other：
"""
from selenium import webdriver
import time
from selenium.webdriver.common.by import By


class TestStart():  # 获取driver对象
    def loadDriver(self):  # 本地驱动加载配置指定测试地址
        driver = webdriver.Chrome()
        # D:\chromedriver_win32\chromedriver_win32\chromedriver.exe
        driver.maximize_window()
        driver.implicitly_wait(10)  # 设置等待时间
        # driver.get(url)
        return driver

    def loadLogin(self, driver, url, username, paw):  # 通用登录

        driver.get(url)
        time.sleep(2)
        driver.find_element(By.ID, "username").click()
        driver.find_element(By.ID, "password").send_keys(paw)
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.CSS_SELECTOR, ".ant-btn").click()

    # 退出系统
    def quit(self, driver, xpath):
        try:
            driver.find_element(By.XPATH, xpath).click()
        finally:
            driver.save_screenshot('退出失败.png')  # 截图
            print('退出失败')
